﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace EventCommandDemo
{
    public abstract class Model : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members

        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

    public sealed class Contact : Model
    {
        #region Fields
        private string _image;
        public bool _isDownloaded;
        #endregion

        #region Properties

        public string DisplayName { get; set; }

        public string Image
        {
            get { return _image; }
            set
            {
                if (_image != value)
                {
                    _image = value;
                    NotifyPropertyChanged("Image");
                }
            }
        }

        public bool IsDownloaded
        {
            get { return _isDownloaded; }
            set
            {
                if (_isDownloaded != value)
                {
                    _isDownloaded = value;
                    NotifyPropertyChanged("IsDownloaded");
                }
            }
        }
        #endregion

        #region Operations
        public void Download()
        {
            Image = "Images/Contact.png";
            IsDownloaded = true;
        }
        #endregion
    }

    public sealed class EmailMessage : Model
    {
        #region Fields
        private Contact _from;
        private string _content;
        private string _attachment;
        private bool _isRead;
        #endregion

        #region Properties

        public Contact From
        {
            get { return _from; }
            set
            {
                if (_from != value)
                {
                    _from = value;
                    NotifyPropertyChanged("From");
                }
            }
        }

        public string Content
        {
            get { return _content; }
            set
            {
                if (_content != value)
                {
                    _content = value;
                    NotifyPropertyChanged("Content");
                }
            }
        }

        public string Attachment
        {
            get { return _attachment; }
            set
            {
                if (_attachment != value)
                {
                    _attachment = value;
                    NotifyPropertyChanged("Attachment");
                }
            }
        }

        public bool IsRead
        {
            get { return _isRead; }
            set
            {
                if (_isRead != value)
                {
                    _isRead = value;
                    NotifyPropertyChanged("IsRead");
                }
            }
        }

        public bool IsDownloaded { get; set; }
        public string Subject { get; set; }
        public DateTime Received { get; set; }
        #endregion

        #region Operations
        public void Download()
        {
            Content = "Full content has been downloaded";
            Attachment = "email_logo.jpg";
            IsDownloaded = true;
        }

        public void MarkAsRead()
        {
            IsRead = true;
        }
        #endregion
    }
}
